import Vue from 'vue'
import Antd from 'ant-design-vue';
import App from './App.vue'
import router from './router'
import store from './store'
import 'ant-design-vue/dist/antd.css';
import VueLazyload from 'vue-lazyload'
import Router from "vue-router"
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}

Vue.config.productionTip = false
Vue.use(Antd);

Vue.use(VueLazyload, {
  preLoad: 1.3,
  loading: require('../src/assets/img/loading3.gif'),
  attempt: 1
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

router.beforeEach((to, from, next) => {
  //用vuex里的方法
  //判断store.getters.getIsLogin===false; 就进来
  if (store.getters.getIsLogin === false) {
    if (to.path == '/login') {
      //如果是这两个的话就让它正常的显示
      next();
    } else {
      alert('还没有登录,请先登录,或者注册')
      next('/login');
    }
  }else{
    next();
  }
})
